from tkinter import *
from tkinter import messagebox
from go_mail import go_mail
from configparser import ConfigParser

def message():
    msg = go_mail(Server_Entry.get(),From_Entry.get(),Passwd_Entry.get())
    a=msg.go_mail(To_Entry.get(),Title_Entry.get(),Content_Entry.get('1.0','end'))
    if a==True:
        messagebox.showinfo('Tips:','发送成功!')
        Title_Entry.delete(0,END)
        Content_Entry.delete('1.0','end')
        window.update()
    else:
        messagebox.showinfo('Tips:','发送失败!')

window = Tk()
window.title('邮件发送软件')
window.geometry('500x300')
window.resizable(0,0)

zhuti = Label(window, text='邮件发送软件', font=('黑体',20))
zhuti.place(x=150,y=0)

From_text = Label(window, text='发件人：',font=('Arial',15))
From_text.place(x=0,y=40)
From_Entry = Entry(window)
From_Entry.place(x=80,y=45)

Passwd_text = Label(window, text='密码：',font=('Arial',15))
Passwd_text.place(x=0,y=80)
Passwd_Entry = Entry(window,show='*')
Passwd_Entry.place(x=80,y=85)

Server_text = Label(window,text='服务器：',font=('Arial',15))
Server_text.place(x=0,y=120)
Server_Entry = Entry(window)
Server_Entry.place(x=80,y=125)

To_text = Label(window, text='收件人：',font=('Arial',15))
To_text.place(x=0,y=160)
To_Entry = Entry(window)
To_Entry.place(x=80,y=165)

Title_text = Label(window,text='主题：',font=('Arial',15))
Title_text.place(x=240,y=40)
Title_Entry = Entry(window)
Title_Entry.place(x=310,y=45)

Content_text = Label(window,text='内容：',font=('Arial',15))
Content_text.place(x=240,y=80)
Content_Entry = Text(window,width=30,height=10)
Content_Entry.place(x=250,y=110)

Sending_Button = Button(window,text='发送',width=6,command=lambda:message())
Sending_Button.place(x=400,y=260)

config = ConfigParser()
config.read('config.ini',encoding='gbk')

From_Entry.insert('0',config['autofill']['User'])
Passwd_Entry.insert('0',config['autofill']['Password'])
Server_Entry.insert('0',config['autofill']['Server'])
To_Entry.insert('0',config['autofill']['Recipient'])
Title_Entry.insert('0',config['autofill']['Subject'])
Content_Entry.insert('0.0',config['autofill']['Content'])

window.mainloop()